package com.lzh.controller;

import com.lzh.dao.AccountMapper;
import com.lzh.pojo.User;
import com.lzh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    AccountMapper accountMapper;

    @RequestMapping("/login")
    public String login(String username, String password , HttpServletRequest request, Model model){
        User user = userService.login(username,password);
        System.out.println("进入");
        if (user != null){
            HttpSession session = request.getSession();
            //登录成功将user存进session之中
            session.setAttribute("user",user);
            model.addAttribute("list",accountMapper.selectAllAccount());
            return "queryAll";
        }
        return "Login";
    }

}
